<template>
  <div>
    <van-nav-bar title="账户设置" @click-left="goback">
      <template #left>
        <van-icon name="arrow-left" size="18" />
      </template>
    </van-nav-bar>
    <div class="title" @click="xuanze" v-text="text"></div>
    <van-action-sheet v-model="show" :round="false">
      <van-datetime-picker
        v-model="currentDate"
        type="date"
        title="选择生日"
        :min-date="minDate"
        :max-date="maxDate"
        @cancel="quxiao"
        @confirm="wancheng"
      />
    </van-action-sheet>
  </div>
</template>

<script>
export default {
  name: "userbirthday",
  data() {
    return {
      text: "选择您的生日",
      show: true,
      minDate: new Date(1850, 0, 1),
      maxDate: new Date(2022, 11, 31),
      currentDate: "",
      update_birthday_id: JSON.parse(localStorage.getItem("waimai")).user_id,
    };
  },
  created() {
      this.currentDate = this.$route.params.birthday
  },
  methods: {
    goback() {
      this.$router.go(-1);
    },
    xuanze() {
      this.show = true;
    },
    quxiao() {
      this.show = false;
    },
    wancheng() {
      this.text = this.currentDate.toLocaleDateString()

      setTimeout(() => {
          this.$router.go(-1)
      }, 50);
      var tmp_obj = {
        update_birthday_id: this.update_birthday_id,
        userbirthday: this.text
      }
      this.axios({
        method: "post",
        url: "http://localhost:3000/update_information",
        data: tmp_obj,
      })
        .then((res) => {
          console.log(res);
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style scoped>
.van-icon {
  color: black;
}

.title {
  height: 60px;
  line-height: 60px;
  font-size: 22px;
  text-align: center;
  background-color: white;
  margin-top: 10px;
}
</style>